package com.cloud.bssp.juc.reetrantlock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @description： 可重入特性测试
 * @author：weirx
 * @date：2021/12/13 14:17
 * @version：3.0
 */
public class Test {

    static ReentrantLock lock = new ReentrantLock(true);
    public static void main(String[] args) {
        method1();
    }
    public static void method1() {
        lock.lock();
        try {
            System.out.println("method1");
            method2();
        } finally {
            lock.unlock();
            System.out.println("method1 unlock");
        }
    }
    public static void method2() {
        lock.lock();
        try {
            System.out.println("method2");
            method3();
        } finally {
            lock.unlock();
            System.out.println("method2 unlock");
        }
    }
    public static void method3() {
        lock.lock();
        try {
            System.out.println("method3");
        } finally {
            lock.unlock();
            System.out.println("method3 unlock");
        }
    }
}
